#include "headfiles.h"

using namespace std;

int main(int argc, char **argv) {
    if (argc != 3) {
        cout << "Usage: " << argv[0] << " file k" << endl;
        return 0;
    }

    fstream fs;
    fs.open(argv[1], iostream::in);
    if (!fs.is_open()) {
        cout << "File " << argv[1] << " open error!" << endl;
        return 1;
    }

    int k = atoi(argv[2]);

    vector<int> vec;
    string str;
    while (fs >> str) {
        if (str.empty()) {
            break;
        }

        int val = atoi(str.c_str());
        vec.push_back(val);
    }
    fs.close();

    size_t size = vec.size();
    int *a = new int[size];
    if (a == NULL) {
        cout << "Allocate array buffer error!" << endl;
        return 1;
    }

    vector<int>::iterator it;
    int i = 0;
    for (it = vec.begin(); it != vec.end(); it++) {
        a[i++] = *it;
    }

    int min_val = minPartition(a, size, k);
    min_val = partitionDP(a, size, k);
    cout << "Min val(DP) is " << min_val << endl;
    
    min_val = partitionBinarySearch(a, size, k);
    cout << "Min val(Binary search) is " << min_val << endl;

    vec.clear();

    return 0;
}
